package cn.c3n.demo.service;

import cn.c3n.demo.domain.Girl;
import cn.c3n.demo.domain.Result;
import cn.c3n.demo.enums.ResultEnum;
import cn.c3n.demo.exception.GirException;
import cn.c3n.demo.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import javax.transaction.Transactional;

@Service
public class GirlService {

    @Autowired
    GirlRepository girlRepository;

    @Transactional
    public void insertTwo()
    {
        Girl a = new Girl();
        a.setAge(18);
        a.setCupSize("F");
        girlRepository.save(a);

        Girl b = new Girl();
        b.setCupSize("GG");
        b.setAge(18);
        girlRepository.save(b);
    }

    public  void getAge(Integer id) throws Exception {
        Girl girl = girlRepository.getOne(id);
        Integer age = girl.getAge();
        if(age < 10)
        {
            //返回你还在上小学吧
            //return 1;
            throw new GirException(ResultEnum.PRIMARY_SCHOOL);
        }
        else if(age > 10 && age < 16)
        {
            //返回 你可能在上初中
            //return 2;
            throw new GirException(ResultEnum.MIDDLE_SCHOOL);
        }

        //如果>16 加钱
        //...
        //return 0;
    }

    /**
     * 查找一位女生
     * @param id
     * @return
     */
    public Girl findOne(Integer id)
    {
        return girlRepository.findOne(id);
    }
}
